package com.jy.adscm.operation.base.service.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.operation.base.bean.JyCustomerProvider;
import com.jy.adscm.operation.base.bean.JyProviderGoods;
import com.jy.adscm.operation.base.mapper.mysql.JyCustomerProviderMapper;
import com.jy.adscm.operation.base.mapper.mysql.JyProviderGoodsMapper;
import com.jy.adscm.operation.base.service.JyProviderGoodsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-11-29
 */
@Service
public class JyProviderGoodsServiceImpl extends ServiceImpl<JyProviderGoodsMapper, JyProviderGoods> implements JyProviderGoodsService {
     @Autowired
     JyCustomerProviderMapper jyCustomerProviderMapper;
    @Override
    public List<JyProviderGoods> selectByTid(String tid) {
        Wrapper<JyProviderGoods> wrapper =new EntityWrapper<>();
        wrapper.eq("goods_id",tid);
        List<JyProviderGoods> jyProviderGoods = super.selectList(wrapper);
        for (JyProviderGoods jyProviderGood : jyProviderGoods) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(jyProviderGood.getProviderId(),null)){
                JyCustomerProvider jyCustomerProvider = jyCustomerProviderMapper.selectById(jyProviderGood.getProviderId());
                jyProviderGood.setJyCustomerProvider(jyCustomerProvider);
            }

        }
        return jyProviderGoods;
    }

    @Override
    public List<JyCustomerProvider> selectAll() {
        Wrapper<JyCustomerProvider> wrapper=new EntityWrapper();
         wrapper.setSqlSelect("ID", "NAME");
        List<JyCustomerProvider> jyCustomerProviders = jyCustomerProviderMapper.selectList(wrapper);
        return jyCustomerProviders;
    }
}
